﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Guru.Data;
using Telerik.Web.UI;

public partial class FE_CustomerDetails : HSMPage
{
    protected int GuestID
    {
        get 
        {
            if (!IsSecureQueryString || string.IsNullOrEmpty(SecureQueryString["GuestID"]))
            {
                return 0;
            }
            else 
            {
                return int.Parse(SecureQueryString["GuestID"].ToString());
            }
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        this.PageType = GuruPageType.Modal;
        this.FixedModalWidth = HSMConstants.DefaultFixedModalWidth;

        if (!IsPostBack)
        {
            if (this.GuestID <= 0)
            {
                this.uxContainerTransHistory.Visible = false;
                this.uxCheckIn.Visible = false;
            }
            else
            {
                this.uxCustomerDetails.GuestID = this.GuestID;
                this.uxCustomerDetails.LoadGuest();
            }
        }
    }
    protected void uxSave_Click(object sender, EventArgs e)
    {
        this.uxCustomerDetails.Save();       
        this.CloseModal(1, "parent.ReloadPage();");
    }

    protected void uxTransactionGrid_ItemCommand(object sender, GridCommandEventArgs e)
    {
        if (e.CommandName == "CheckIn")
        {
            string link = string.Format("CheckInModal.aspx?{0}", BuildSecureQueryString("GuestID=" + this.GuestID + "&InvoiceID=" + e.CommandArgument));
            Response.Redirect(link);
        }
    }
    protected void uxTransactionGrid_ItemDataBound(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridDataItem)
        {
            DataRowView dv = e.Item.DataItem as DataRowView;
            LinkButton checkIn = e.Item.FindControl("uxCheckIn") as LinkButton;
            HSMEnums.TransactionType type = (HSMEnums.TransactionType)Enum.Parse(typeof(HSMEnums.TransactionType), dv["TransactionType"].ToString());
            HSMEnums.BookingStatus status = (HSMEnums.BookingStatus)Enum.Parse(typeof(HSMEnums.BookingStatus), dv["Status"].ToString());
            if (type == HSMEnums.TransactionType.Reservation && status == HSMEnums.BookingStatus.Active)
            {
                checkIn.Visible = true;
                checkIn.CommandArgument = dv["TransID"].ToString();
            }
            else checkIn.Visible = false;
        
        }
    }
    protected void uxTransactionGrid_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
    {
        if (this.GuestID > 0)
        {
            GuruParameterCollection parameters = new GuruParameterCollection();
            parameters.AddUserLoggedParams();
            parameters.Add("@GuestID", this.GuestID, DbType.Int32);

            uxTransactionGrid.DataSource = HSMCommon.HSMBusiness.GetDataTable("spa_HSM_Guest_GetTransHistory", parameters);
        }
        uxTransactionGrid.Columns.FindByUniqueName("Name" + this.CurrentLanguage).Visible = true;
    }


    protected void uxCheckIn_Click(object sender, EventArgs e)
    {
        Response.Redirect(string.Format("CheckInModal.aspx?{0}", BuildSecureQueryString("GuestID=" + this.GuestID)));
    }
    protected void uxBooking_Click(object sender, EventArgs e)
    {
        Response.Redirect(string.Format("CheckInModal.aspx?{0}&mode=2", BuildSecureQueryString("GuestID=" + this.GuestID)));
    }
    
}
